/*
 *  Copyright 2010 Wesley Gooch, Ryan Nix, Cody Wenzel.
 *  Montana State University - Spring Semester 2010
 *  Computer Science 450 - Compilers
 *  Project: Micro-Pascal Compiler
 */

package msu.compiler.scanner.fsas;

import msu.compiler.scanner.Tokenizer;
import msu.compiler.scanner.Token;

/**
 * FSA to determine a GreaterThen or GreaterThenOrEqualTo Token.
 *
 * @author Wesley Gooch
 */
public class GreaterThanFSA extends FSA {

    public GreaterThanFSA(Tokenizer tokenizer) {
        super(tokenizer);
        initializeStates(3);
    }

    /**
     * Executes the GreaterThanFSA state machine.
     *
     * @pre     The tokenizer is pointing at the first character of the
     *          current token which must be a >.
     *
     * @post    The tokenizer is pointing at the first character after
     *          the current token.
     *          A token has been generated.
     *          The token's lexeme contains either > or >=
     */
    public void execute() {
        Character currentChar;
        while(notFinished()) {
            currentChar = getCurrentChar();
            switch(getCurrentState()){
                case 0:
                    if(currentChar == '>') {
                       setAcceptState("s1", Token.MP_GTHAN);
                       peekAhead();
                    } else {
                        fail();
                    }
                    break;
                case 1:
                    if(currentChar == '=') {
                        setAcceptState("s1", Token.MP_GEQUAL);
                        finish();
                    } else {
                        fail();
                    }
                    break;
                default:
                    fail();
                    break;
            }
        }

    }

}
